package com.sailfish.springbootdemo.dao.db2;

import com.sailfish.springbootdemo.common.DB2TableName;
import com.sailfish.springbootdemo.pojo.db2.PcbSizeFactoryValue;
import org.apache.ibatis.annotations.*;
import org.apache.ibatis.type.JdbcType;

import java.util.List;

public interface PcbMatchFactoryValueDao {
    @Results(id = "pcbMatchFactoryValueResultMap", value = {
            @Result(column = "id", property = "id", jdbcType = JdbcType.INTEGER),
            @Result(column = "son_factory_id", property = "sonFactoryId", jdbcType = JdbcType.INTEGER),
            @Result(column = "pcb_match_param_key", property = "pcbMatchParamKey", jdbcType = JdbcType.VARCHAR),
            @Result(column = "pcb_match_param_value", property = "pcbMatchParamValue", jdbcType = JdbcType.VARCHAR),
            @Result(column = "remark", property = "remark", jdbcType = JdbcType.VARCHAR),
            @Result(column = "create_time", property = "createTime", jdbcType = JdbcType.DATETIMEOFFSET),
            @Result(column = "update_time", property = "updateTime", jdbcType = JdbcType.DATETIMEOFFSET),
            @Result(column = "status", property = "status", jdbcType = JdbcType.INTEGER),
            @Result(column = "sort", property = "sort", jdbcType = JdbcType.INTEGER),
            @Result(column = "create_user", property = "createUser", jdbcType = JdbcType.VARCHAR),
            @Result(column = "update_user", property = "updateUser", jdbcType = JdbcType.VARCHAR),
    })
    /*
     * 查询单个
     */
    @Select("<script> " +
            "select *" +
            " from " + DB2TableName.PCB_MATCH_FACTORY_VALUE +
            "<where> " +
            "<if test='id != null'>" +
            " and id = #{id}" +
            "</if>" +
            "</where> " +
            " order by sort" +
            "</script>")
    PcbSizeFactoryValue getById(@Param("id") Integer id);

    @Select("<script> " +
            "select *" +
            " from " + DB2TableName.PCB_MATCH_FACTORY_VALUE +
            "<where> " +
            "<if test='id != null'>" +
            " and id = #{id}" +
            "</if>" +
            "<if test='sonFactoryId != null'>" +
            " and son_factory_id = #{sonFactoryId}" +
            "</if>" +
            "<if test='pcbMatchParamKey != null'>" +
            " and pcb_match_param_key = #{pcbMatchParamKey}" +
            "</if>" +
            "</where> " +
            " order by sort" +
            "</script>")
    @ResultMap(value = "pcbMatchFactoryValueResultMap")
    List<PcbSizeFactoryValue> getByLimit(PcbSizeFactoryValue pcbSizeFactoryValue);

    /*
     *新增所有列
     */
    @Insert("insert into " + DB2TableName.PCB_MATCH_FACTORY_VALUE + " (son_factory_id, pcb_match_param_key, pcb_match_param_value, remark, create_time, create_user, update_time, update_user, status, sort) values " +
            "(#{sonFactoryId}, #{pcbMatchParamKey}, #{pcbMatchParamValue}, #{remark}, #{createTime}, #{createUser}, #{updateTime}, #{updateUser}, #{status}, #{sort})")
    @Options(useGeneratedKeys = true, keyProperty = "id")
    Integer insert(PcbSizeFactoryValue param);

    /*
     *通过主键删除
     */
    @Delete("delete from " + DB2TableName.PCB_MATCH_FACTORY_VALUE + " where id = #{id} ")
    Integer delete(@Param("id") Integer id);

    /*
     *通过主键修改数据
     */
    @Update("<script>" +
            "update " + DB2TableName.PCB_MATCH_FACTORY_VALUE +
            "<set>" +
            "<if test='sonFactoryId != null '>" +
            "   son_factory_id  = #{sonFactoryId}," +
            "</if>" +
            "<if test='pcbMatchParamKey != null and pcbMatchParamKey != \"\" '>" +
            "   pcb_match_param_key  = #{pcbMatchParamKey}," +
            "</if>" +
            "<if test='pcbMatchParamValue != null and pcbMatchParamValue != \"\" '>" +
            "   pcb_match_param_value  = #{pcbMatchParamValue}," +
            "</if>" +
            "<if test='remark != null and remark != \"\" '>" +
            "   remark  = #{remark}," +
            "</if>" +
            "<if test='sort != null'>" +
            "    sort = #{sort}," +
            "</if>" +
            "<if test='status != null'>" +
            "    status = #{status}," +
            "</if>" +
            "<if test='createTime != null'>" +
            "    create_time = #{createTime}," +
            "</if>" +
            "<if test='updateTime != null'>" +
            "    update_time = #{updateTime}," +
            "</if>" +
            "<if test='createUser != null and createUser != \"\"'>" +
            "    create_user = #{createUser}," +
            "</if>" +
            "<if test='updateUser != null and updateUser != \"\"'>" +
            "    update_user = #{updateUser}," +
            "</if>" +
            "</set>" +
            "where id = #{id}" +
            "</script>")
    Integer update(PcbSizeFactoryValue param);
}
